package com.draw.cli.webclient;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.draw.cli.config.ConfigManager;

public abstract class Client {
	private static final Logger logger = LoggerFactory.getLogger(Client.class);
	private static String ip;
	private static int port;

	protected static boolean isConfigChanged() {
		return !((port == ConfigManager.getInstance().getPortServer()) && ip
				.equals(ConfigManager.getInstance().getIpServer()));
	}

	protected static URL getURL(String service) throws MalformedURLException {
		ip = ConfigManager.getInstance().getIpServer();
		port = ConfigManager.getInstance().getPortServer();
		String txt = "http://" + ip + ":" + port + "/" + service + "?wsdl";
		logger.info("Creating service at {}", txt);
		return new URL(txt);
	}

	protected static QName getQName(String service) {
		return new QName("http://draw.some.com/", service);
	}

	protected static Service getService(String service)
			throws MalformedURLException {
		return Service.create(getURL(service), getQName(service));
	}
}
